//
//  MineVC.m
//  Meum
//
//  Created by 黄卫 on 17/2/24.
//  Copyright © 2017年 huangwei. All rights reserved.
//

#import "MineVC.h"
#import "TYCustomNavgationCotr.h"
#import "OrderManageVC.h";
#import "TYPersonInfoVC.h";
#import "SettingVC.h"
#import "MySampleVC.h"
#import "AdviceController.h"
#import "HomeMemberVC.h"
@interface MineVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UIView *headView;
@end

@implementation MineVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
//    UIView *head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
//    head.backgroundColor = [UIColor greenColor];
    self.tableView.tableHeaderView = self.headView;
    
    [self.view addSubview:self.tableView];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory=[paths objectAtIndex:0];//Documents目录
    NSLog(@"NSDocumentDirectory:%@",documentsDirectory);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UIView *)headView
{
    if (NULL == _headView)
    {
        _headView =  [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 211)];
        
        UIButton *imgView = [[UIButton alloc] init];
        CGFloat wh = 80;
        imgView.frame = CGRectMake((Screen_Width-wh)/2, 30, wh, wh);
        [imgView setBackgroundImage:[UIImage imageNamed:@"icon_home1"] forState:UIControlStateNormal];
        [_headView addSubview:imgView];
        [imgView addTarget:self action:@selector(iconTouch:) forControlEvents:UIControlEventTouchUpInside];
        CGFloat w = 60;
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake((Screen_Width-w)/2, CGRectGetMaxY(imgView.frame)+20, w, 25)];
        nameLabel.tag = 666666;
        nameLabel.font = FontCustomSize(18);
        nameLabel.text = @"huang";
        [_headView addSubview:nameLabel];
        
        UIImageView *writeImg = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(nameLabel.frame)+30, CGRectGetMaxY(imgView.frame)+20, 30, 30)];
        writeImg.image = [UIImage imageNamed:@"icon_home1"];
        [_headView addSubview:writeImg];
        _headView.backgroundColor = RGB(229,229,229);
        
        
    }
    return _headView;
}

-(void)iconTouch:(UIButton *)btn{
    TYPersonInfoVC *personVc = [[TYPersonInfoVC alloc] init];
    [self.navigationController pushViewController:personVc animated:YES];
}



-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UITableView groupedTableView];
    }
    return _tableView;
    
//    if (!_tableView) {
//        _tableView = [[UITableView alloc] init];
//        _tableView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
//    }
//    _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
////    _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, kTableViewTopSpace)];
//    _tableView.rowHeight = kDefaultCellHeight;
//    _tableView.backgroundColor = Color_BackGround;
//    _tableView.separatorColor = RGB(229,229,229);
//    _tableView.sectionHeaderHeight = 0.01;
//    _tableView.sectionFooterHeight = kTableViewTopSpace;
//    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, 0.01)];
//    return _tableView;
}

#pragma mark UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section ==0) {
        return 2;
    }else if(section == 1){
        return 1;
    }else{
        return 3;
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            cell.textLabel.text = @"我的订单";
        }else{
            cell.textLabel.text = @"我的样本";
        }
    }else if (indexPath.section==1){
            cell.textLabel.text = @"家庭成员";
    }else{
        if (indexPath.row==0) {
            cell.textLabel.text = @"去评分";
        }else if (indexPath.row ==1){
            cell.textLabel.text = @"意见与建议";
        }else{
            cell.textLabel.text = @"设置";
        }
    }
    cell.imageView.image = [UIImage imageNamed:@"icon_home1"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            OrderManageVC *orderManageVc = [[OrderManageVC alloc] init];
            [self.navigationController pushViewController:orderManageVc animated:YES];
        }else{
            MySampleVC *sampleVc = [[MySampleVC alloc] init];
            [self.navigationController pushViewController:sampleVc animated:YES];
        }
    }else if (indexPath.section==1){
            HomeMemberVC *homeVc = [[HomeMemberVC alloc] init];
            [self.navigationController pushViewController:homeVc animated:YES];
    }else{
        if (indexPath.row==0) {
            
        }else if (indexPath.row ==1){
            AdviceController *adviceVc = [[AdviceController alloc] init];
            [self.navigationController pushViewController:adviceVc animated:YES];
        }else{
            SettingVC *settingVc = [[SettingVC alloc] init];
            [self.navigationController pushViewController:settingVc animated:YES];
        }
    }
}

@end
